package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DeviceManage;
import com.ruoyi.system.service.IDeviceManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备管理Controller
 * 
 * @author 王国飞
 * @date 2023-06-20
 */
@RestController
@RequestMapping("/system/manage")
public class DeviceManageController extends BaseController
{
    @Autowired
    private IDeviceManageService deviceManageService;

    /**
     * 查询设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceManage deviceManage)
    {
        startPage();
        List<DeviceManage> list = deviceManageService.selectDeviceManageList(deviceManage);
        return getDataTable(list);
    }

    /**
     * 导出设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:manage:export')")
    @Log(title = "设备管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceManage deviceManage)
    {
        List<DeviceManage> list = deviceManageService.selectDeviceManageList(deviceManage);
        ExcelUtil<DeviceManage> util = new ExcelUtil<DeviceManage>(DeviceManage.class);
        util.exportExcel(response, list, "设备管理数据");
    }

    /**
     * 获取设备管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:manage:query')")
    @GetMapping(value = "/{deviceNumber}")
    public AjaxResult getInfo(@PathVariable("deviceNumber") Long deviceNumber)
    {
        return success(deviceManageService.selectDeviceManageByDeviceNumber(deviceNumber));
    }

    /**
     * 新增设备管理
     */
    @PreAuthorize("@ss.hasPermi('system:manage:add')")
    @Log(title = "设备管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceManage deviceManage)
    {
        return toAjax(deviceManageService.insertDeviceManage(deviceManage));
    }

    /**
     * 修改设备管理
     */
    @PreAuthorize("@ss.hasPermi('system:manage:edit')")
    @Log(title = "设备管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceManage deviceManage)
    {
        return toAjax(deviceManageService.updateDeviceManage(deviceManage));
    }

    /**
     * 删除设备管理
     */
    @PreAuthorize("@ss.hasPermi('system:manage:remove')")
    @Log(title = "设备管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceNumbers}")
    public AjaxResult remove(@PathVariable Long[] deviceNumbers)
    {
        return toAjax(deviceManageService.deleteDeviceManageByDeviceNumbers(deviceNumbers));
    }
}
